package com.easyaop.core.matcher;

import com.easyaop.api.advisor.Advisor;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

public class ProxyElementMatcher implements ElementMatcher<MethodDescription> {
    private final Advisor advisor;

    private final ElementMatcher<MethodDescription> elementMatcher;

    public ProxyElementMatcher(Advisor advisor, ElementMatcher<MethodDescription> elementMatcher) {
        this.advisor = advisor;
        this.elementMatcher = elementMatcher;
    }

    @Override
    public boolean matches(MethodDescription target) {
        boolean matches = elementMatcher.matches(target);
        if (matches && advisor != null) {
//            target.getOwnership().getDeclaringClass()
//            target.getDeclaringType().getTypeName();
//            String string = target.toString();
//            System.out.println(string);
//            advisor.addSignature("com.easyaop.test.core.entity.MyBean#say([[Ljava/lang/Object;)Ljava/lang/String;");
//            advisor.addSignature("com.easyaop.test.core.entity.MyBean#say([[Ljava/lang/Object;)Ljava/lang/String;");
            String signature = target.getDeclaringType().getTypeName() + "#" + target.getName() + target.getDescriptor();
//            System.out.println("add "+signature);
            advisor.addSignature(signature);
        }
        return matches;
    }
}
